﻿using PocketRPG_Trails.Scripts.Effects;
using UnityEngine;

namespace com.winter.effect
{
    public class TestMyTrail : MonoBehaviour
    {
        public WeaponTrail weaponTrail;

        private float t = 0.033f;
        private float tempT;

        private float animationIncrement = 0.003f;

        private void Start()
        {
            weaponTrail.SetTime(0, 0, 1f);
        }

        private void LateUpdate()
        {
            t = Mathf.Clamp(Time.deltaTime, 0, 0.066f);

            if (t > 0)
            {
                while (tempT < t)
                {
                    tempT += animationIncrement;

                    if (weaponTrail.time > 0)
                    {
                        weaponTrail.Itterate(Time.time - t + tempT);
                    }
                    else
                    {
                        weaponTrail.ClearTrail();
                    }
                }

                tempT -= t;

                if (weaponTrail.time > 0)
                {
                    weaponTrail.UpdateTrail(Time.time, t);
                }
            }
        }

        /// <summary>
        /// 开始进行拖尾
        /// </summary>
        public void trailStart()
        {
            weaponTrail.SetTime(2.0f, 0, 1f);
        }
    }
}